<template>
	<view class="consent">
		<nav-bars backState="1000" :bgColor="navBackground" fontColor="#000" title="账单" ></nav-bars>
		<view class="wrapper">
			<view class="listBox" v-if="list.length>0" v-for="(item ,index) in list" :key="index">
				<view class="months flex">
					<view class="monthLeft flex" @click="pickTime">
						<text>{{year}}年{{month}}月</text>
						<!-- <text>{{item.pay_date}}</text> -->
						<image :src="`${baseImg}/static/adminShop/collectionCode/icon_down.png`" class="icon_down">
						</image>
					</view>
					<view class="monthRight">
						<text>收入</text>
						<text>￥{{item.total_amount}}</text>
					</view>
				</view>
				<view class="item-list flex"  v-for="(items ,indexs) in item.records" :key="indexs" @tap="goJumps(items)">
					<view class="sidebarLeft flex">
						<image :src="items.headimg" class="portrait"></image>
						<view class="areaBlock">
							<view class="titles text-overflow">{{items.nickname}}</view>
							<view class="date">{{formatDate(items.pay_at)}}</view>
						</view>
					</view>
					<view class="sidebarRight">
						<text>+</text>{{items.pay_amount}}
					</view>
				</view>
			</view>
			<view class="listBox" v-if="list.length<=0">
				<view class="months flex">
					<view class="monthLeft flex" @click="pickTime">
						<text>{{year}}年{{month}}月</text>
						<!-- <text>{{item.pay_date}}</text> -->
						<image :src="`${baseImg}/static/adminShop/collectionCode/icon_down.png`" class="icon_down">
						</image>
					</view>
				</view>
				<view class="no-card">
				    <image src="../../../static/demo/suess.png"></image>
				    <view class="no-title">当月您还没有收款订单哦~~</view>
				    <text>先去逛一逛吧~</text>
				</view>
			</view>
		</view>
		<u-picker mode="time" @confirm="pickTimeOk" v-model="showTime" :params="params"></u-picker>
	</view>
</template>

<script>
	import service_now from '@/service/now.js';
	export default {
		components: {},
		data() {
			return {
				baseImg: this.$static,
				navBackground: '',
				code: '',
				page:1,
				pagesize:10,
				list:[],
				total:0,
				showTime:false,
				year_month:'',//年月
				year:new Date().getFullYear(),
				month:new Date().getMonth()+1<10?'0'+(new Date().getMonth()+1):new Date().getMonth()+1,
				params: {
					year: true,
					month: true,
					day: false,
					hour: false,
					minute: false,
					second: false
				},
			}
		},
		onLoad() {
			let year=new Date().getFullYear();
			let yearCut=year.toString().substr(2,year.length);
			this.year_month=yearCut+this.month;
			this.getBillRecord();
		},
		onReachBottom() {
			if(this.page*this.pagesize<=this.total){
				this.page++;
				this.getBillRecord();
			}
		},
		methods: {
			getBillRecord() {
              service_now.billRecords({
				  page:this.page,
				  pagesize:this.pagesize,
				  store_id:this.$store.state.index.sid,
				  switch_date:this.year_month,
				  }).then(res => {
					  this.total=res.data.total;
              		if (res.code == 1 && res.data.records.length>0) {
						let data=res.data.records;
						this.list=[...this.list,...data];
              		}else{
						this.list=[];
					}
              })
			},
			/**
			 * 时间戳格式化秒
			 * @param {Object} value
			 */
			formatDate(value) {
				let date = new Date(parseInt(value) * 1000);
				let y = date.getFullYear();
				let m = date.getMonth() + 1;
				m = m < 10 ? "0" + m : m;
				let d = date.getDate();
				d = d < 10 ? "0" + d : d;
				let h = date.getHours();
				h = h < 10 ? "0" + h : h;
				let minute = date.getMinutes();
				let second = date.getSeconds();
				minute = minute < 10 ? "0" + minute : minute;
				second = second < 10 ? "0" + second : second;
				return m + "-" + d + " " + h + ":" + minute + ":" + second;
				//return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
			},
			goJumps(params){
				let data={
					headimg:params.headimg,
					nickname:params.nickname,
					pay_amount:params.pay_amount,
					order_status:params.order_status,
					order_id:params.order_id,
					pay_at:params.pay_at,
					user_mobile:params.user_mobile,
					memo:params.memo
				};
				console.log('===',params.order_id)
				uni.navigateTo({
					url: '/pages_now/pages/mall/store/orderBillDetails?params='+encodeURIComponent(JSON.stringify(data))
				});
			},
			// 时间选择
			pickTime(){
				this.showTime = true
			},
			// 弹框确定
			pickTimeOk(e){
				console.log(e,'时间选择确定')
				this.year = e.year;
				this.month = e.month;
				let year=e.year.toString().substr(2,e.year.length);
				this.year_month=year+ e.month;
				this.getBillRecord();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.consent {
		width: 100%;

		.wrapper {
			width: 94%;
			margin: 20rpx auto;

			.listBox {
				width: 100%;
				height: auto;
				margin-bottom: 58rpx;

				.months {
					width: 100%;
					height: 100rpx;
					line-height: 100rpx;
					justify-content: space-between;

					.monthLeft {
						width: 45%;
						font-size: 28rpx;
						color: #252525;
						font-weight: bold;
						color: #252525;
						align-items: center;

						.icon_down {
							width: 18rpx;
							height: 10rpx;
							margin-left: 14rpx;
						}
					}

					.monthRight {
						width: 208rpx;
						height: 37rpx;
						font-size: 26rpx;
						font-weight: 500;
						text-align: right;
						color: #464646;
					}
				}

				.item-list {
					width: 100%;
					align-items: center;
                    height: 118rpx;
					margin-bottom:8rpx;
					.sidebarLeft {
						align-items: center;
						justify-content: space-between;

						.portrait {
							width: 76rpx;
							height: 76rpx;
							border-radius: 50%;
						}

						.areaBlock {
							flex: 1;
							margin-left: 20rpx;

							.titles {
								width: 210rpx;
								height: 50rpx;
								font-size: 32rpx;
								color: #464646;
							}

							.date {
								width: 293rpx;
								height: 37rpx;
								font-size: 26rpx;
								color: #A6A6A6;
							}
						}
					}

					.sidebarRight {
						width: 45%;
						height: 48rpx;
						text-align: right;
						font-size: 40rpx;
						color: #CB9439;
					}
				}
			}
		}

		.text-overflow {
			overflow: hidden;
			text-overflow: ellipsis;
			-o-text-overflow: ellipsis;
			white-space: nowrap;
		}

		.flex {
			display: flex;
		}
		.no-card {
		    display: flex;
		    flex-direction: column;
		    align-items: center;
		    justify-content: center;
		    border-radius: 20rpx 20rpx 0 0;
		    padding-top: 40rpx;
		}
		
		.no-title {
		    padding: 30rpx 0;
		}
		.no-card image {
		    height: 232rpx;
		    width: 288rpx;
		    padding: 40rpx;
		}
		.no-card>text {
		    font-size: 24rpx;
		    color: #999;
		}
	}
</style>
